const localStorage =
    typeof window === 'undefined'
        ? undefined
        : window.localStorage;

const UNIQUE_PREFIX = `TEST_ADMIN:`;

export const get = (key:string) => {
    if (!localStorage) {
        return null;
    }
    key = `${UNIQUE_PREFIX}${key}`;
    return JSON.parse(<string>localStorage.getItem(key));
};

export const set = (key:string, value:string) => {
    if (!localStorage) {
        return null;
    }
    key = `${UNIQUE_PREFIX}${key}`;
    localStorage.setItem(key, JSON.stringify(value));
};

export const remove = (key:string) => {
    if (!localStorage) {
        return null;
    }
    key = `${UNIQUE_PREFIX}${key}`;
    localStorage.removeItem(key);
};

export const clear = () => {
    if (!localStorage) {
        return null;
    }
    localStorage.clear();
};

export default {
    get,
    set,
    remove,
    clear
};
